package com.example.qxfw.dataBaseManager.nyzjk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.qxfw.common.entity.ny.CropGrowdateIndexlib;
import com.example.qxfw.common.entity.ny.CropWeatherDistIndexlib;
import com.example.qxfw.common.mapper.CropGrowDateIndexLibMapperXml;
import com.example.qxfw.common.mapper.CropWeatherDistIndexlibMapperXml;
import com.example.qxfw.dataBaseManager.nyzjk.service.QxzhzbkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/6  星期四   10:00
 * @description : 此类用来
 ***************************************/
@Service
public class QxzhzbkServiceImpl implements QxzhzbkService {

    @Autowired
    private CropGrowDateIndexLibMapperXml cropGrowDateIndexLibMapperXml;

    @Autowired
    private CropWeatherDistIndexlibMapperXml cropWeatherDistIndexlibMapperXml;

    @Override
    public List<CropGrowdateIndexlib> selectDistinct(String field,String cropname) {
        List<CropGrowdateIndexlib> cropnameList = this.cropGrowDateIndexLibMapperXml.querySelect(field, cropname);
        return cropnameList;
    }

    @Override
    public List<CropWeatherDistIndexlib> selectAll() {
        List<CropWeatherDistIndexlib> cropWeatherDistIndexlibs = this.cropWeatherDistIndexlibMapperXml.selectList(null);
        return cropWeatherDistIndexlibs;
    }

    @Override
    public List<CropWeatherDistIndexlib> querySelect(final CropWeatherDistIndexlib cropWeatherDistIndexlib) {
        return this.cropWeatherDistIndexlibMapperXml.selectList(new LambdaQueryWrapper<CropWeatherDistIndexlib>()
                .like(StringUtils.isNotBlank(cropWeatherDistIndexlib.getCropname()), CropWeatherDistIndexlib::getCropname, cropWeatherDistIndexlib.getCropname())
                .like(StringUtils.isNotBlank(cropWeatherDistIndexlib.getEasyhappentype()), CropWeatherDistIndexlib::getEasyhappentype, cropWeatherDistIndexlib.getEasyhappentype())
                .like(StringUtils.isNotBlank(cropWeatherDistIndexlib.getGrowthdate()), CropWeatherDistIndexlib::getGrowthdate, cropWeatherDistIndexlib.getGrowthdate())
        );
    }

    @Override
    public Integer saveCropWeatherDistIndexLib(final CropWeatherDistIndexlib cropWeatherDistIndexlib) {
        return this.cropWeatherDistIndexlibMapperXml.insertSelective(cropWeatherDistIndexlib);
    }

    @Override
    public Integer updateCropWeatherDistIndexLib(final CropWeatherDistIndexlib cropWeatherDistIndexlib) {
        return this.cropWeatherDistIndexlibMapperXml.updateByPrimaryKeySelective(cropWeatherDistIndexlib);
    }

    @Override
    public Integer deleteCropWeatherDistIndexLib(final CropWeatherDistIndexlib cropWeatherDistIndexlib) {
        return this.cropWeatherDistIndexlibMapperXml.deleteById(cropWeatherDistIndexlib.getId());
    }
}
